const fs = require('fs');
module.exports = {
    'get-canvas-children': function (event) {
        let path = 'db://assets/resources/testJson.json';
        // let path = Editor.Project.path + '/assets/resources/testJson2.json';
        // let path2 = `${Editor.Project.path}/assets/testJson1.json`;
        let srcData;
        if (fs.existsSync(Editor.url(path))) {
            srcData = fs.readFileSync(Editor.url(path));
            srcData = srcData && JSON.parse(srcData);
        }
        var canvas = cc.find('Canvas');
        let count = 0;
        // Editor.log('path', Editor.url(path))
        // Editor.log('srcData', srcData)
        if (srcData) {
            count = srcData.data.count;
        }
        canvas.walk(v => {
            count++;
        })
        // Editor.log('children length : ' + count);
        let dataObject = {
            data: {
                count: count,
            }
        }
        let data = JSON.stringify(dataObject);
        // Editor.log('路径', path, typeof path);
        // fs.writeFileSync(path, JSON.stringify(data));
        // Editor.assetdb.create(path)
        Editor.assetdb.createOrSave(path, data)
        // Editor.assetdb.create('db://assets/testJson1.json');

        // Editor.assetdb.refresh(path);
        if (event.reply) {
            event.reply(null, count);
        }
    },
    'print': function (event, uuid) {
        Editor.log('uuid', uuid)
        let count = 0;
        Editor.assetdb.queryPathByUrl(uuid, function (err, info) {
            Editor.log('info', info);
        })
        // node.walk(v => {
        //     count++;
        // })
        // Editor.log('count', count)
    }
}